package com.xiaotu.service.sync;

import cn.hutool.core.collection.CollUtil;
import com.xiaotu.entity.StarDeleteRecordModel;
import com.xiaotu.entity.TvDeleteRecordModel;
import com.xiaotu.service.mysql.MysqlStarService;
import com.xiaotu.service.mysql.MysqlTvService;
import com.xiaotu.service.pgsql.PgsqlStarService;
import com.xiaotu.service.pgsql.PgsqlTvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhangxiao
 * @create 2021-09-24 8:47
 */
@Service
@Transactional
public class SyncDeleteRecordService {

    @Autowired
    private PgsqlTvService pgsqlTvService;

    @Autowired
    private MysqlTvService mysqlTvService;

    @Autowired
    private MysqlStarService mysqlStarService;

    @Autowired
    private PgsqlStarService pgsqlStarService;

    public void syncStarDeleteRecord() {
        List<StarDeleteRecordModel> list = pgsqlStarService.getStarDeleteRecords();
        if (CollUtil.isNotEmpty(list))
            mysqlStarService.clearDeleteRecord();mysqlStarService.batchInsertDeleteRecord(list);
    }

    public void syncTvDeleteRecord() {
        List<TvDeleteRecordModel> list = pgsqlTvService.getTvDeleteRecords();
        if (CollUtil.isNotEmpty(list))
            mysqlTvService.clearDeleteRecord();mysqlTvService.batchInsertDeleteRecord(list);
    }

    @Transactional
    public void syncDeleteRecord() {
        syncStarDeleteRecord();
        syncTvDeleteRecord();
    }
}
